<template>
	<zPopup v-model="applyPopup" type="2000">
		<view class="banner_swiper_box">
			<swiper class="banner_swiper" :autoplay="false" :interval="3000" previous-margin="40px" next-margin="40px" :duration="1000"
			 @change="onSwiperChange" :current="swiperIndex">
				<swiper-item>
					<view class="banner_img" :class="{ active: swiperIndex == 0 }">
						<view class="primary">
							<image src="../../static/icon/shengBa/ic_chuji_a.png" mode="aspectFill"></image>
						</view>
						<view class="price_box">
							￥<text>{{primaryInfo.price}}</text>
						</view>
						<view class="tips ">{{primaryInfo.instruction}}</view>
						<view class="word">即买即得</view>
						<view class="word">价值<text>{{primaryInfo.value}}</text>元大礼包</view>
						<image class="gift" src="../../static/icon/shengBa/ic_chuji.png" mode="aspectFill"></image>
						<text class="mention">购买资格 一经售岀 概不退款</text>
						<button class="buy" @click="onPageJump('/pages/welfare/welfareAgency?type=' + 1000)">购买{{primaryInfo.typeStr}}礼包</button>
					</view>
				</swiper-item>
				<swiper-item>
					<view class="banner_img" :class="{ active: swiperIndex == 1 }">
						<view class="primary">
							<image src="../../static/icon/shengBa/ic_gaoji_a.png" mode="aspectFill"></image>
						</view>
						<view class="price_box">
							￥<text>{{seniorInfo.price}}</text>
						</view>
						<view class="tips yellow">{{seniorInfo.instruction}}</view>
						<view class="word gold">即买即得</view>
						<view class="word gold">价值<text>{{seniorInfo.value}}</text>元大礼包</view>
						<image class="gift" src="../../static/icon/shengBa/ic_gaoji.png" mode="aspectFill"></image>
						<text class="mention">购买资格 一经售岀 概不退款</text>
						<button class="buy active" @click="onPageJump('/pages/welfare/welfareAgency?type=' + 2000)">购买{{seniorInfo.typeStr}}礼包</button>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="swiper_pages">
			<view class="pages" :class="{ active: swiperIndex == 0 }"></view>
			<view class="pages" :class="{ active: swiperIndex == 1 }"></view>
		</view>
		<view class="close" @click="applyPopup = false">
			<image src="../../static/icon/shengBa/ic_guanbi.png" mode=""></image>
		</view>
	</zPopup>
</template>

<script>
	import zPopup from "@/components/common/popup";
	export default {
		components: {
			zPopup,
		},
		props: {
			//是否显示
			value: {
				type: Boolean,
				default: function() {
					return false;
				},
			},
		},
		data() {
			return {
				applyPopup: false,
				primaryInfo:'',
				seniorInfo:'',
				swiperIndex: 0,
			};
		},
		created() {
			if (this.value) {
				this.applyPopup = this.value;
			}
		},
		watch: {
			value(val) {
				this.applyPopup = val;
				this.loadData();
			},
			applyPopup(val) {
				this.$emit("input", val);
			}
		},
		mounted() {},
		methods: {
			onPageJump(url) {
				uni.navigateTo({
					url: url
				});
				// this.applyPopup = false;
			},
			// 轮播图变化
			onSwiperChange(e) {
				console.log(e.detail.current);
				this.swiperIndex = e.detail.current;
			},
			loadData(){
				this.$http.get('api/mime/member/v1/gift', {
					type: 'primary'
				}).then(res => {
					this.primaryInfo = res;
				})
				this.$http.get('api/mime/member/v1/gift', {
					type: 'senior'
				}).then(res => {
					this.seniorInfo = res;
				})
			}
		},
	};
</script>

<style lang="scss" scoped>
	.banner_swiper_box {
		width: 100vw;
		position: relative;

		.banner_swiper {
			height: 850upx;

			swiper-item {
				position: relative;
				box-sizing: border-box;
				display: flex;
				align-items: flex-end;

				.banner_img {
					position: relative;
					border-radius: 20rpx;
					width: 590rpx;
					//height: 790rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					transform: scale(0.9);
					transition: all 0.4s;
					background-color: #fff;
					padding: 80rpx 40rpx 40rpx 40rpx;

					&.active {
						transform: scale(1);
					}

					.price_box {
						font-size: 24rpx;
						color: #ff3e3e;

						text {
							font-size: 48rpx;
						}
					}

					.tips {
						font-size: 24rpx;
						color: #999999;
					}

					.yellow {
						color: #cca56b;
					}

					.word {
						font-family: PangMenZhengDao;
						font-size: 36rpx;
						color: #333333;

						text {
							font-size: 48rpx;
							color: #ff3e3e;
						}

						&:nth-child(4) {
							margin-top: 40rpx;
						}
					}

					.gold {
						color: #8e611f;
					}

					.gift {
						width: 355rpx;
						height: 273rpx;
					}

					.mention {
						margin-top: 24rpx;
						font-size: 24rpx;
						color: #ff3e3e;
					}

					.buy {
						width: 100%;
						margin-top: 24rpx;
						background-image: linear-gradient(90deg,#a1de6c 0%,#7ac23c 100%);
						height: 88rpx;
						border-radius: 44rpx;
						line-height: 88rpx;
						font-size: 32rpx;
						color: #fff;
					}

					.active {
						background-image: linear-gradient(270deg,
							#d1ba77 0%,
							#f7e8ad 100%) !important;
					}

					.primary {
						z-index: 20;
						position: absolute;
						top: -74rpx;
						left: 50%;
						transform: translateX(-50%);

						image {
							width: 477rpx;
							height: 153rpx;

						}
					}
				}
			}
		}
	}
	.close {
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 40rpx;
	
		image {
			width: 60rpx;
			height: 60rpx;
		}
	}
	.swiper_pages {
		//z-index: 50;
		margin-top: 24rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	
		.pages {
			margin: 0 6rpx;
			width: 36rpx;
			height: 6rpx;
			background-color: #ffffff;
			border-radius: 4rpx;
	
			&.active {
				background-color: #7ac23c;
			}
		}
	}
</style>
